import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';
import 'package:ball_lion/widgets/max_bottom_sheet.dart';
import 'package:ball_lion/service/config_service.dart';
import 'package:ball_lion/resources/colours.dart';

class LiveSettingSheet extends StatefulWidget {
  const LiveSettingSheet({super.key});

  @override
  State<LiveSettingSheet> createState() => _LiveSettingSheetState();
}

class _LiveSettingSheetState extends State<LiveSettingSheet> {
  ConfigService configService = Get.find<ConfigService>();
  PushConfig pushConfig = Get.find<ConfigService>().pushConfig;

  @override
  Widget build(BuildContext context) {
    return MaxBottomSheet(
        onClosing: () {},
        shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
        backgroundColor: Colours.white,
        clipBehavior: Clip.antiAlias,
        builder: (context) => Padding(
              padding: const EdgeInsets.fromLTRB(16, 16, 16, 0),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const QsText("播放器设置",
                      fontSize: 16, fontWeight: FontWeight.w500),
                  Row(
                    children: [
                      const QsText("后台播放(应用退至后台,可继续播放声音)",
                          color: Colours.grey66),
                      const Spacer(),
                      Transform.scale(
                        scale: 0.8,
                        child: CupertinoSwitch(
                          value: pushConfig.liveBackground == 1,
                          activeColor: Colours.main,
                          onChanged: (value) {
                            pushConfig.liveBackground = value ? 1 : 0;
                            configService.update(ConfigType.liveBackground,
                                pushConfig.liveBackground);
                            setState(() {});
                          },
                        ),
                      )
                    ],
                  ).paddingSymmetric(vertical: 16)
                ],
              ),
            ));
  }
}
